{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import necessary dependencies and settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import datetime\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from dateutil.parser import parse\n",
    "import pytz"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load and process sample temporal data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-13 15:45:05.755000-07:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012-01-20 22:30:00.254000+05:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2016-12-25 00:30:00.000000+10:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Time\n",
       "0  2015-03-08 10:30:00.360000+00:00\n",
       "1  2017-07-13 15:45:05.755000-07:00\n",
       "2  2012-01-20 22:30:00.254000+05:30\n",
       "3  2016-12-25 00:30:00.000000+10:00"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time_stamps = ['2015-03-08 10:30:00.360000+00:00', '2017-07-13 15:45:05.755000-07:00',\n",
    "               '2012-01-20 22:30:00.254000+05:30', '2016-12-25 00:30:00.000000+10:00']\n",
    "df = pd.DataFrame(time_stamps, columns=['Time'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([Timestamp('2015-03-08 10:30:00.360000+0000', tz='UTC'),\n",
       "       Timestamp('2017-07-13 15:45:05.755000-0700', tz='pytz.FixedOffset(-420)'),\n",
       "       Timestamp('2012-01-20 22:30:00.254000+0530', tz='pytz.FixedOffset(330)'),\n",
       "       Timestamp('2016-12-25 00:30:00+1000', tz='pytz.FixedOffset(600)')], dtype=object)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts_objs = np.array([pd.Timestamp(item) for item in np.array(df.Time)])\n",
    "df['TS_obj'] = ts_objs\n",
    "ts_objs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Date based features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "      <th>Year</th>\n",
       "      <th>Month</th>\n",
       "      <th>Day</th>\n",
       "      <th>Quarter</th>\n",
       "      <th>DayOfWeek</th>\n",
       "      <th>DayName</th>\n",
       "      <th>DayOfYear</th>\n",
       "      <th>WeekOfYear</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>2015</td>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>Sunday</td>\n",
       "      <td>67</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-13 15:45:05.755000-07:00</td>\n",
       "      <td>2017</td>\n",
       "      <td>7</td>\n",
       "      <td>13</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>Thursday</td>\n",
       "      <td>194</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012-01-20 22:30:00.254000+05:30</td>\n",
       "      <td>2012</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>Friday</td>\n",
       "      <td>20</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2016-12-25 00:30:00.000000+10:00</td>\n",
       "      <td>2016</td>\n",
       "      <td>12</td>\n",
       "      <td>25</td>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>360</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Time  Year  Month  Day  Quarter  DayOfWeek  \\\n",
       "0  2015-03-08 10:30:00.360000+00:00  2015      3    8        1          6   \n",
       "1  2017-07-13 15:45:05.755000-07:00  2017      7   13        3          3   \n",
       "2  2012-01-20 22:30:00.254000+05:30  2012      1   20        1          4   \n",
       "3  2016-12-25 00:30:00.000000+10:00  2016     12   25        4          6   \n",
       "\n",
       "    DayName  DayOfYear  WeekOfYear  \n",
       "0    Sunday         67          10  \n",
       "1  Thursday        194          28  \n",
       "2    Friday         20           3  \n",
       "3  Saturday        360          51  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Year'] = df['TS_obj'].apply(lambda d: d.year)\n",
    "df['Month'] = df['TS_obj'].apply(lambda d: d.month)\n",
    "df['Day'] = df['TS_obj'].apply(lambda d: d.day)\n",
    "df['DayOfWeek'] = df['TS_obj'].apply(lambda d: d.dayofweek)\n",
    "df['DayName'] = df['TS_obj'].apply(lambda d: d.weekday_name)\n",
    "df['DayOfYear'] = df['TS_obj'].apply(lambda d: d.dayofyear)\n",
    "df['WeekOfYear'] = df['TS_obj'].apply(lambda d: d.weekofyear)\n",
    "df['Quarter'] = df['TS_obj'].apply(lambda d: d.quarter)\n",
    "\n",
    "df[['Time', 'Year', 'Month', 'Day', 'Quarter', \n",
    "    'DayOfWeek', 'DayName', 'DayOfYear', 'WeekOfYear']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Time based features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "      <th>Hour</th>\n",
       "      <th>Minute</th>\n",
       "      <th>Second</th>\n",
       "      <th>MUsecond</th>\n",
       "      <th>UTC_offset</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>10</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>360000</td>\n",
       "      <td>00:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-13 15:45:05.755000-07:00</td>\n",
       "      <td>15</td>\n",
       "      <td>45</td>\n",
       "      <td>5</td>\n",
       "      <td>755000</td>\n",
       "      <td>-1 days +17:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012-01-20 22:30:00.254000+05:30</td>\n",
       "      <td>22</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>254000</td>\n",
       "      <td>05:30:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2016-12-25 00:30:00.000000+10:00</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10:00:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Time  Hour  Minute  Second  MUsecond  \\\n",
       "0  2015-03-08 10:30:00.360000+00:00    10      30       0    360000   \n",
       "1  2017-07-13 15:45:05.755000-07:00    15      45       5    755000   \n",
       "2  2012-01-20 22:30:00.254000+05:30    22      30       0    254000   \n",
       "3  2016-12-25 00:30:00.000000+10:00     0      30       0         0   \n",
       "\n",
       "         UTC_offset  \n",
       "0          00:00:00  \n",
       "1 -1 days +17:00:00  \n",
       "2          05:30:00  \n",
       "3          10:00:00  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Hour'] = df['TS_obj'].apply(lambda d: d.hour)\n",
    "df['Minute'] = df['TS_obj'].apply(lambda d: d.minute)\n",
    "df['Second'] = df['TS_obj'].apply(lambda d: d.second)\n",
    "df['MUsecond'] = df['TS_obj'].apply(lambda d: d.microsecond)\n",
    "df['UTC_offset'] = df['TS_obj'].apply(lambda d: d.utcoffset())\n",
    "\n",
    "df[['Time', 'Hour', 'Minute', 'Second', 'MUsecond', 'UTC_offset']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "      <th>Hour</th>\n",
       "      <th>TimeOfDayBin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>10</td>\n",
       "      <td>Morning</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-13 15:45:05.755000-07:00</td>\n",
       "      <td>15</td>\n",
       "      <td>Afternoon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012-01-20 22:30:00.254000+05:30</td>\n",
       "      <td>22</td>\n",
       "      <td>Night</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2016-12-25 00:30:00.000000+10:00</td>\n",
       "      <td>0</td>\n",
       "      <td>Late Night</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Time  Hour TimeOfDayBin\n",
       "0  2015-03-08 10:30:00.360000+00:00    10      Morning\n",
       "1  2017-07-13 15:45:05.755000-07:00    15    Afternoon\n",
       "2  2012-01-20 22:30:00.254000+05:30    22        Night\n",
       "3  2016-12-25 00:30:00.000000+10:00     0   Late Night"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hour_bins = [-1, 5, 11, 16, 21, 23]\n",
    "bin_names = ['Late Night', 'Morning', 'Afternoon', 'Evening', 'Night']\n",
    "df['TimeOfDayBin'] = pd.cut(df['Hour'], \n",
    "                            bins=hour_bins, labels=bin_names)\n",
    "df[['Time', 'Hour', 'TimeOfDayBin']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "      <th>UTC_offset</th>\n",
       "      <th>TZ_info</th>\n",
       "      <th>TimeZones</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>00:00:00</td>\n",
       "      <td>UTC</td>\n",
       "      <td>[WET, UTC, UCT, GMT]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-13 15:45:05.755000-07:00</td>\n",
       "      <td>-1 days +17:00:00</td>\n",
       "      <td>pytz.FixedOffset(-420)</td>\n",
       "      <td>[MST, GMT+7, PDT]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012-01-20 22:30:00.254000+05:30</td>\n",
       "      <td>05:30:00</td>\n",
       "      <td>pytz.FixedOffset(330)</td>\n",
       "      <td>[IST]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2016-12-25 00:30:00.000000+10:00</td>\n",
       "      <td>10:00:00</td>\n",
       "      <td>pytz.FixedOffset(600)</td>\n",
       "      <td>[VLAT, ChST, AEST, PGT, DDUT, GMT-10, CHUT]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Time        UTC_offset                 TZ_info  \\\n",
       "0  2015-03-08 10:30:00.360000+00:00          00:00:00                     UTC   \n",
       "1  2017-07-13 15:45:05.755000-07:00 -1 days +17:00:00  pytz.FixedOffset(-420)   \n",
       "2  2012-01-20 22:30:00.254000+05:30          05:30:00   pytz.FixedOffset(330)   \n",
       "3  2016-12-25 00:30:00.000000+10:00          10:00:00   pytz.FixedOffset(600)   \n",
       "\n",
       "                                     TimeZones  \n",
       "0                         [WET, UTC, UCT, GMT]  \n",
       "1                            [MST, GMT+7, PDT]  \n",
       "2                                        [IST]  \n",
       "3  [VLAT, ChST, AEST, PGT, DDUT, GMT-10, CHUT]  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['TZ_info'] = df['TS_obj'].apply(lambda d: d.tzinfo)\n",
    "df['TimeZones'] = df['TS_obj'].apply(lambda d: list({d.astimezone(tz).tzname() \n",
    "                                   for tz in map(pytz.timezone, \n",
    "                                                 pytz.all_timezones_set)\n",
    "                                       if d.astimezone(tz).utcoffset() == d.utcoffset()}))\n",
    "\n",
    "df[['Time', 'UTC_offset', 'TZ_info', 'TimeZones']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "      <th>TimeUTC</th>\n",
       "      <th>Epoch</th>\n",
       "      <th>GregOrdinal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>1.425811e+09</td>\n",
       "      <td>735665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-13 15:45:05.755000-07:00</td>\n",
       "      <td>2017-07-13 22:45:05.755000+00:00</td>\n",
       "      <td>1.499986e+09</td>\n",
       "      <td>736523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012-01-20 22:30:00.254000+05:30</td>\n",
       "      <td>2012-01-20 17:00:00.254000+00:00</td>\n",
       "      <td>1.327079e+09</td>\n",
       "      <td>734522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2016-12-25 00:30:00.000000+10:00</td>\n",
       "      <td>2016-12-24 14:30:00+00:00</td>\n",
       "      <td>1.482590e+09</td>\n",
       "      <td>736322</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Time                          TimeUTC  \\\n",
       "0  2015-03-08 10:30:00.360000+00:00 2015-03-08 10:30:00.360000+00:00   \n",
       "1  2017-07-13 15:45:05.755000-07:00 2017-07-13 22:45:05.755000+00:00   \n",
       "2  2012-01-20 22:30:00.254000+05:30 2012-01-20 17:00:00.254000+00:00   \n",
       "3  2016-12-25 00:30:00.000000+10:00        2016-12-24 14:30:00+00:00   \n",
       "\n",
       "          Epoch  GregOrdinal  \n",
       "0  1.425811e+09       735665  \n",
       "1  1.499986e+09       736523  \n",
       "2  1.327079e+09       734522  \n",
       "3  1.482590e+09       736322  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['TimeUTC'] = df['TS_obj'].apply(lambda d: d.tz_convert(pytz.utc))\n",
    "df['Epoch'] = df['TimeUTC'].apply(lambda d: d.timestamp())\n",
    "df['GregOrdinal'] = df['TimeUTC'].apply(lambda d: d.toordinal())\n",
    "\n",
    "df[['Time', 'TimeUTC', 'Epoch', 'GregOrdinal']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "      <th>TimeUTC</th>\n",
       "      <th>DaysElapsedEpoch</th>\n",
       "      <th>DaysElapsedOrdinal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>2015-03-08 10:30:00.360000+00:00</td>\n",
       "      <td>860.207396</td>\n",
       "      <td>860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-13 15:45:05.755000-07:00</td>\n",
       "      <td>2017-07-13 22:45:05.755000+00:00</td>\n",
       "      <td>1.696917</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012-01-20 22:30:00.254000+05:30</td>\n",
       "      <td>2012-01-20 17:00:00.254000+00:00</td>\n",
       "      <td>2002.936564</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2016-12-25 00:30:00.000000+10:00</td>\n",
       "      <td>2016-12-24 14:30:00+00:00</td>\n",
       "      <td>203.040734</td>\n",
       "      <td>203</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Time                          TimeUTC  \\\n",
       "0  2015-03-08 10:30:00.360000+00:00 2015-03-08 10:30:00.360000+00:00   \n",
       "1  2017-07-13 15:45:05.755000-07:00 2017-07-13 22:45:05.755000+00:00   \n",
       "2  2012-01-20 22:30:00.254000+05:30 2012-01-20 17:00:00.254000+00:00   \n",
       "3  2016-12-25 00:30:00.000000+10:00        2016-12-24 14:30:00+00:00   \n",
       "\n",
       "   DaysElapsedEpoch  DaysElapsedOrdinal  \n",
       "0        860.207396                 860  \n",
       "1          1.696917                   2  \n",
       "2       2002.936564                2003  \n",
       "3        203.040734                 203  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "curr_ts = datetime.datetime.now(pytz.utc)\n",
    "# compute days elapsed since today\n",
    "df['DaysElapsedEpoch'] = (curr_ts.timestamp() - df['Epoch']) / (3600*24)\n",
    "df['DaysElapsedOrdinal'] = (curr_ts.toordinal() - df['GregOrdinal']) \n",
    "\n",
    "df[['Time', 'TimeUTC', 'DaysElapsedEpoch', 'DaysElapsedOrdinal']]"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
